clear
do "...\First.do"

********************************************************************************
clear 
use "$work\full_sample.dta"

keep if year==2019

merge m:1 pnr using "$work\survey_and_sample_clean.dta"
drop if _merge==2
drop _merge

keep if inrange(age,40,70)

g interact=low_ses*yder_ses_max


********************************************************************************
* Recode
recode q221_1 (4=1) (1=2) (2=3) (5=4) (3=5), g(q221_1b)
recode q221_2 (4=1) (1=2) (2=3) (5=4) (3=5), g(q221_2b)
recode q221_3 (4=1) (1=2) (2=3) (5=4) (3=5), g(q221_3b)
recode q221_4 (4=1) (1=2) (2=3) (5=4) (3=5), g(q221_4b)
recode q221_5 (4=1) (1=2) (2=3) (5=4) (3=5), g(q221_5b)



foreach var of varlist q221_1b q221_2b q221_3b q221_4b q221_5b  {
	
	egen mean_`var'=mean(`var')
	egen sd_`var'=sd(`var')
	g `var'_sd=(`var'-mean_`var')/sd_`var'
}

summ *_sd

********************************************************************************



sum q221_1b_sd, d
local mean=round(`r(mean)'*1000/1000, 0.00001)
local sd=round(`r(sd)'*1000/1000, 0.00001)

ttest q221_1b_sd if yder_ses_max==0, by(low_ses)
local mean0=round((`r(mu_2)'-`r(mu_1)')*1000/1000, 0.00001)

areg q221_1b_sd low_ses yder_ses_max interact i.age male non_dk partner, a(ydernr) cluster(ydernr)

outreg2 using "$table\survey_items_sd_yder.tex",  keep(low_ses yder_ses_max interact) replace tex word nocons bdec(5) sdec(5) rdec(5) addtext(Gradient for high SES physicians, `mean0', Outcome mean, `mean')



foreach var of varlist q221_2b_sd q221_3b_sd q221_4b_sd q221_5b_sd {
	
sum `var', d
local mean=round(`r(mean)'*1000/1000, 0.00001)
local sd=round(`r(sd)'*1000/1000, 0.00001)

ttest `var' if yder_ses_max==0, by(low_ses)
local mean0=round((`r(mu_2)'-`r(mu_1)')*1000/1000, 0.00001)

areg `var' low_ses yder_ses_max interact i.age male dk, a(ydernr) cluster(ydernr)

outreg2 using "$table\survey_items_sd_yder.doc", keep(low_ses yder_ses_max interact) append tex word nocons bdec(5) sdec(5) rdec(5) addtext(Gradient for high SES physicians, `mean0', Outcome mean, `mean')

	
}

